package com.hundsun.s3.platform.monitor.service.impl;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.hundsun.s3.common.util.BaseDao;



/**
 * 
 * <p>Title:SrCount</p>
 * <p>Description: 计算总的平均服务，接单时间差和单个服务人员的，平均服务，接单时间差</p>
 * <p>Company: Hundsun</p>
 * @author :zhangwc23609
 * @date :2018年3月8日 下午4:02:23
 */
@Service
public class SrCount extends BaseDao{
	
	/**
	 * 
	 * @Description:根据服务人员id计算接单时间的平均值
	 * @param staffId
	 * @return
	 * @author: zhangwc23609
	 * @date: 2018年3月8日 下午4:42:55
	 */
	public String getAvgTakingTimeById(String staffId) {
		//得到记录总数
		double count = 0;
		double oneTime = 0;
		Map<String, Object> params = new HashMap<>();
		params.put("staffId", staffId);
		List<Map<String, String>> list = this.call("600102",params);
		if(list.size() != 0){
			Map<String, String> map = list.get(0);
			if(map.size() != 0){
				String sCount = map.get("totalCount");
				count = Double.parseDouble(sCount);
			}
		}
		//得到接单时间总长
		List<Map<String,String>> time = this.call("600107", params);
		if(time.size() != 0){
			Map<String, String> map = time.get(0);
			if(map.size() != 0){
				String soneTime = map.get("oneTime");
				oneTime = Double.parseDouble(soneTime);
			}
		}
		//计算平均值
		DecimalFormat df = new DecimalFormat("#0.000");
		if(count == 0.0) {
			return "0";
		}
		String avgTakingTime = df.format(oneTime/count);
		
		return avgTakingTime;
	}
	
	/**
	 * 
	 * @Description:根据服务人员id，计算服务时间的平均值
	 * @param staffId
	 * @return
	 * @author: zhangwc23609
	 * @date: 2018年3月8日 下午5:27:59
	 */
	public String getAvgChatTimeById(String staffId) {
		//得到记录总数
		double count = 0.0;
		double oneChatTime = 0.0;
		Map<String, Object> params = new HashMap<>();
		params.put("staffId", staffId);
		List<Map<String, String>> list = this.call("600102",params);
		if(list.size() != 0){
			Map<String, String> map = list.get(0);
			if(map.size() != 0){
				String sCount = map.get("totalCount");
				count = Double.parseDouble(sCount);
			}
		}
		//得到服务时间总长
		List<Map<String,String>> time = this.call("600108", params);
		if(time.size() != 0){
			Map<String, String> map = time.get(0);
			if(map.size() != 0){
				String soneChatTime = map.get("oneChatTime");
				oneChatTime = Double.parseDouble(soneChatTime);
			}
		}
		//计算平均值
		DecimalFormat df = new DecimalFormat("#0.000");
		if(count == 0.0) {
			return "0";
		}
		String avgChatTime = df.format(oneChatTime/count);
		
		return avgChatTime;
	}
	
}
